<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }
  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }
  .rj-cell.note label{
    float: left;
  }
  .rj-cell.note span{
    width: 80%;
    display: inline-block;
  }
  .weui-cells {
    margin-top: 0;
  }
  .weui-cells_form {
    background: #fbfbfb;
  }
  .weui-cell {
    background: #fff;
  }
  .weui-cells__title {
    text-align: left;
  }
  .oitem {
    padding: 3px;
  }
  .hide {
    display: none;
  }
  #acts {
    font-size: 0;
  }
  #acts span {
    font-size: 14px;
  }
  .halfbtn {
    display: inline-block;
    width: 49%;
  }
  .weui-label {
    text-align: left;
  }

  .weui_uploader_input_wrp {
    float: left;
    position: relative;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 77px;
    height: 77px;
    border: 1px solid #D9D9D9;
  }
  .weui_uploader_hd {
    padding-top: 0;
    padding-right: 0;
    padding-left: 0;
  }
  .weui_uploader_files {
    list-style: none;
  }
  .weui_uploader_input_wrp:before {
    width: 2px;
    height: 39.5px;
  }
  .weui_uploader_input_wrp:before, .weui_uploader_input_wrp:after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    background-color: #D9D9D9;
  }
  .weui_uploader_input {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  }
  .weui_uploader_input_wrp:after {
    width: 39.5px;
    height: 2px;
  }
  .weui_uploader_bd {
    overflow: hidden;
  }
  .weui_cell {
    padding: 10px 15px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    background: #fff;
  }
  .examine >>> .weui-uploader_files {
    list-style: none;
    overflow-y: hidden;
  }
  .examine >>> .weui-uploader_file {
    float: left;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 79px;
    background: no-repeat 50%;
    background-size: cover;
  }
  .weui-cell_select {
    padding: 0 15px;
  }
</style>
<template>
  <div class="examine">
    <div class="rj-wrap">
      {{title}}
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px" />
      </a>
    </div>
    <div class="weui-cells weui-cells_form">
      <form action="" method="post" id="formid">
        <input type="hidden" name="guid" :value="id" />
        <div class="cellgroup">
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">名称</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" readonly :value="baseInfo.name" name="">
            </div>
          </div>
<!--          <div class="weui-cell">-->
<!--            <div class="weui-cell__hd"><label class="weui-label">批次</label></div>-->
<!--            <div class="weui-cell__bd">-->
<!--              <input class="weui-input" readonly  type="text"  name="" :value="baseInfo.bitchname">-->
<!--            </div>-->
<!--          </div>-->
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">采收主体</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" class="weui-input" name="parta" :value="parta.name" />
              <input type="hidden" name="organizationid" :value="parta.guid" />
              <select class="weui-select" name="" v-model="parta">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in companys" :value="item">
                  {{item.name}}
                </option>
              </select>
<!--              <input class="weui-input" type="text" name="" readonly :value="baseInfo.parta">-->
            </div>
          </div>
            <div class="weui-cell">
              <div class="weui-cell__hd"><label class="weui-label">入库库房</label></div>
              <div class="weui-cell__bd">
                <input type="hidden" name="srguid" :value="room.guid" />
                <input type="hidden" name="srname" :value="room.name" />
                <select class="weui-select" v-model="room">
                  <option value="" disabled>请选择</option>
                  <option v-for="(item, index) in rooms" :key="item.guid" :value="item">
                    {{item.name}}
                  </option>
                </select>
              </div>
            </div>
          <!--          <div class="weui-cell">-->
          <!--            <div class="weui-cell__hd"><label class="weui-label">部门</label></div>-->
          <!--            <div class="weui-cell__bd">-->
          <!--              <input class="weui-input" type="text" name="" readonly :value="baseInfo.departname">-->
          <!--            </div>-->
          <!--          </div>-->
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">乙方</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" readonly :value="baseInfo.partbname">
            </div>
          </div>
          <div class="weui-cell" v-show="baseInfo.type == 1">
            <div class="weui-cell__hd"><label class="weui-label">地块</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text"  name="" readonly :value="baseInfo.arealandname">
            </div>
          </div>
          <div class="weui-cell" v-show="baseInfo.type == 2">
            <div class="weui-cell__hd"><label class="weui-label">农户库</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text"  name="" readonly :value="baseInfo.farmerstore">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">开户行</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text"  name="" readonly :value="baseInfo.bank">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">银行账号</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text"  name="" readonly :value="baseInfo.bankcode">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">产品</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text"  name="" readonly :value="baseInfo.productname">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">规格</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text"  name="" readonly :value="baseInfo.specificationname">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">单价</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" style="display: inline-block; width: 55%;" readonly type="text" name="" :value="baseInfo.price">
              <input v-if="baseInfo.qamaintype == 2" class="weui-input" style="display: inline-block; width: 40%;" readonly type="text" value="元/淀粉含量*吨">
              <input v-else class="weui-input" style="display: inline-block; width: 40%;" readonly type="text" value="元/吨">
            </div>
          </div>
          <div class="weui-cell" v-if="baseInfo.type == 2">
            <div class="weui-cell__hd"><label class="weui-label">采收数量</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" style="display: inline-block; width: 55%;" readonly type="text" name="" :value="baseInfo.weight">
              <input class="weui-input" style="display: inline-block; width: 40%;" readonly type="text" value="吨">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">创建时间</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" readonly type="text" name="" :value="baseInfo.createdate">
            </div>
          </div>
        </div>
        <div ref="actHtml" class="fixcont">
          <div class="weui-btn-area">
            <a class="weui-btn weui-btn_primary halfbtn subbtn" href="javascript:" @click="postForm">提交</a>
            <!--            <a class="weui-btn weui-btn_primary halfbtn subbtn" v-if="refuseflag == 1" href="javascript:" @click="rejectIt">拒绝</a>-->
            <a class="weui-btn weui-btn_primary halfbtn" href="javascript:" @click="$router.back(-1)" id="sub">返回</a>
          </div>
        </div>
      </form>
    </div>
    <div id="bmlogs">
      <SalesOperationLogs2 :nodeid="nodeid" :orderid="id" :srguid="baseInfo.srguid" :departid="baseInfo.departid"></SalesOperationLogs2>
    </div>
  </div>
</template>

<script>
  import SalesOperationLogs2 from '@/components/common/SalesOperationLogs2'

  export default {
    name: 'EditProContract',
    data () {
      return {
        openid: localStorage.openid,
        id: '',
        title: '',
        nodeid: '',
        annex: '',
        baseInfo: '',
        wxParams: {},
        images: {
          serverId: [],
          srcStr: [],
        },
        refuseflag: '',
        refuseNodes: [],
        orderfiles: [],
        rooms: [],
        room: '',
        companys: '',
        parta: ''
      }
    },
    components: {
      SalesOperationLogs2
    },
    mounted () {
      //提交操作定位到页面底部
      //$('#bmlogs').css('margin-bottom', this.$refs.actHtml.offsetHeight)

      //$('#opinion').focus();
      this.id = this.$route.query.guid;
      this.nodeid = this.$route.query.nodeid;
      this.annex = this.$route.query.annex;
      this.title = this.$route.query.title;
      this.refuseflag = this.$route.query.refuseflag;

      if (this.$route.query.status) {
        this.status = this.$route.query.status;
      }

      this.getOrgs();
      // this.getRefuseNodes();
    },
    watch: {
      parta: function (val) {
        this.getRooms(val.guid);
      }
    },
    methods: {
      getOrgs: async function() {
        await this.getBaseInfo(this.id);
        this.axios({
          method: 'get',
          url: '/harvest/Procurementcontract!getoRs.action',
          params: {}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.companys = response.data.orgs;
            this.para = this.companys.filter(item => {
              return this.baseInfo.organizationid == item.guid;
            })[0];
            this.getRooms(this.para.guid);
          } else {
            this.toastText('获取公司数据失败')
          }
        });
      },
      getBaseInfo: async function(id) {
        this.axios({
          method: 'post',
          url: '/harvest/Procurementcontract!getDetail.action',
          params: {contractid: id}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.baseInfo = response.data.contract;

            let cthis = this;
            if (this.rooms != '' && this.room == '') {
              this.room = this.rooms.filter(item => {
                return item.guid == cthis.baseInfo.srguid;
              })[0];
            }
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastError('系统错误');
          }
        });
      },
      getRooms: function(orgid) {
        this.axios({
          method: 'get',
          url: '/produce/Storeroom!getAllStrm.action',
          params: {'entity.orgguid': orgid}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.rooms = response.data.rooms;

            let cthis = this;
            if (this.baseInfo != '' && this.room == '') {
              this.room =this.rooms.filter(item => {
                return item.guid == cthis.baseInfo.srguid;
              })[0];
            }
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastText('获取库房数据失败');
          }
        });
      },
      postForm: function () {
        let that = this;

        if (this.parta == '' || this.parta == undefined) {
          this.toastText('请选择采收主体');
          return false;
        }
        if (this.room == '') {
          this.toastText('入库库房不能为空！');
          return false;
        }
        //防止重复提交
        $('.subbtn').attr("disabled",true).css("pointer-events","none");
        //显示提交状态
        $.showLoading("正在提交");

        let postData = this.serialize2Obj($("#formid").serializeArray());
        // postData.opinion = $('#opinion').val() != '' ? $('#opinion').val() : '同意';
        postData.nodeid = this.nodeid;
        this.axios({
          method: 'post',
          url: '/harvest/Procurementcontract!update.action',
          params: postData
        }).then(response => {
          //恢复提交按钮可点击
          $('.subbtn').attr('disabled', false).css("pointer-events","auto");
          //关闭提交状态
          $.hideLoading();

          if (response.data.msg == 'success') {
            this.toastSuccess('提交成功!');
            this.$router.push({name: 'ProContractList'});
          } else if (response.data.msg == 'canotopt') {
            this.toastText('不允许的操作！');
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastError('系统错误');
          }
        }).catch(function (error) {
          //恢复提交按钮可点击
          $('.subbtn').attr('disabled', false).css("pointer-events","auto");
          //关闭提交状态
          $.hideLoading();
          that.toastError('系统错误');
        });
      },
      openLogs: function() {
        this.$router.push({name: 'SalesOperationLogs2', query: {orderid: this.id}});
      }
    }
  }
</script>
